//******************************COPYRIGHT NOTICE*******************************
//All rights reserved.  This material is confidential and proprietary to 
//CogentSoft (Shen Zhen) Limited and no part of this material should be reproduced, 
//published in any form by any means, electronic or mechanical including
//photocopy or any information storage or retrieval system nor should the
//material be disclosed to third parties without the express written 
//authorization of CogentSoft (Shen Zhen) Limited.
/*
<PRE>
* ******************************PROGRAM DESCRIPTION*****************************
* Program Name   : Globals.java
* Description: Globals object
* Creation Date  : 2006-5-26
* Creator: 开发组
* ******************************************************************************
</PRE>
*/
package com.cogent.common.util;

/**
 * @author: hxh
 * @date: 2006-5-26
 */
public class Globals {

    //
    private static String PATH = null;
    
    public static final String[] MODIFIER_MODIFYDATE = {"modifier","modifydate"};
    
    private static XMLProperty property = null;
    
    /** 空的Integer对象，值为0 */
    public static final Integer EMPTY_INTEGER = new Integer(0);
    /** 状态正常 */
    public static final String NORMAL = "0";
    /** 状态已注销 */
    public static final String RECYCLED = "1";
    /** 状态正常 */
    public static final Long NORMAL_L = Long.valueOf("0");
    /** 已审核 */
    public static final Long CHECKED  = Long.valueOf("1");
    /**删除状态 --- 已删除*/
    public static final String DELETED = "1";
    /**删除状态 --- 未删除*/
    public static final String NOTDELETED = "0";
    
    /**人口死亡状态 --- 死亡**/
    public static final String POPULATE_DEAD = "0";
    /**人口死亡状态 --- 在世**/
    public static final String POPULATE_LIVE = "1";
    
    /**是否，对应于参数中的"SF" **/
    /**否，值='1'**/
    public static final String SF_NO = "0";
    /**是，值='1'**/
    public static final String SF_YES = "1";
    //------------------------------------------->常量 begin
    
    public static final int SELECTION = 1;
    
    public static final int RADIO = 2;
    
    /** 查看 */
    public static final int VIEW = 1;    

    /** 保存 */
    public static final int SAVE = 2;

    /** 更新 */
    public static final int UPDATE = 4;    
    
    /** 注销 */
    public static final int RECYCLE = 8;
    
    /** 恢复 */
    public static final int RESUME = 16;
    
    /** 删除 */
    public static final int DELETE = 32;
    
    /** 审核 */
    public static final int AUDIT = 64;
    
    /** 申报处理 */
    public static final int ACCEPT = 98;

    /** 登录 */
    public static final int LOGON = 99;
    
    /**受理状态---接受申请*/
    public static final int YES = 0;
    
    /**受理状态---拒绝申请*/
    public static final int NO = 3;
    
    /**网上受理状态---*/
    public static final String  web="2";
    
    /**出租屋使用状态--自用 */
    public static final String ZUL_USESTATUS_ZY = "2";
    
    /**出租屋使用状态--出租 */
    public static final String ZUL_USESTATUS_CHZ = "1";
    
    /**出租屋使用状态--待租 */
    public static final String ZUL_USESTATUS_DZ = "3";
    
    /**出租屋使用状态--部分出租 */
    public static final String ZUL_USESTATUS_BFCHZ = "5";
    
    /**出租屋使用状态--其他 2008-07-03 By Sunm */
    public static final String ZUL_USESTATUS_QT = "9";
    
    /**出租屋使用状态--未指定 */
    public static final String ZUL_USESTATUS_WZD = "-1";
    
    /**出租屋使用状态--未统计*/
    public static final String ZUL_USESTATUS_NOSTAT = "-999";
    
    /**出租屋使用状态--空置 */
    public static final String ZUL_USESTATUS_KZH = "4";
    
    /**出租屋是否退租---退租 */
    public static final String ZUL_ISEND_YES = "1";
    
    /**出租屋是否退租---没有退租 */
    public static final String ZUL_ISEND_NO = "0";
    
    /**租住人是否离开--离开 */
    public static final String ZUL_ISDEPART_YES = "1";
    
    /**租住人是否离开--没离开 */
    public static final String ZUL_ISDEPART_NO = "0";
    
    /**是否签约人--是签约人 */
    public static final String ZUL_ISSIGN_YES = "1";
    
    /**是否签约人--不是签约人 */
    public static final String ZUL_ISSIGN_NO = "0";
    
    /**租赁合同终止状态--正常 */
    public static final String ZUL_STOPTYPE_NORMAL = "0";
    
    /**租赁合同终止状态--终止 */
    public static final String ZUL_STOPTYPE_STOP = "1";
    
    /**出租屋综合管理责任书--有 */
    public static final String ZUL_AGREEMENT_YES = "1";
    
    /**出租屋综合管理责任书--无 */
    public static final String ZUL_AGREEMENT_NO = "0";
    
    /**********************低保状态参数************************/
    /**低保发放状态--已发放 */
    public static final String CIV_ASSURE_ISPUTTED = "0";
    
    /**低保发放状态--未发放 */
    public static final String CIV_ASSURE_NOTPUTTED = "1";
    
    /**低保允许发放状态--未通过审批 */
    public static final String CIV_ASSURE_NOTPASS = "0";
    /**低保允许发放状态--发放 */
    public static final String CIV_ASSURE_PUTTING = "1";
    /**低保允许发放状态--停放 */
    public static final String CIV_ASSURE_STOPPUT = "2";
    
    /**低保重新申报状态--审批中**/
    public static final String CIV_REPROP_INAUDIT = "0";
    /**低保重新申报状态--审批未通过,允许重新申报**/
    public static final String CIV_REPROP_ALLOW = "1";
    /**低保重新申报状态--已重新申报,不允许再申报**/
    public static final String CIV_REPROP_NOTALLOW = "2";
    
    /**男性**/
    public static final String GLOBAL_MALE = "1";
    
    /**女性**/
    public static final String GLOBAL_FEMALE = "2";
    
    /**女性改（变）为男性**/
    public static final String GLOBAL_FEMALE2MALE = "5";
    
    /**男性改（变）为女性**/
    public static final String GLOBAL_MALE2FEMALE = "6";  
    
    /**火葬**/
    public static final String GLOBAL_CREMATE = "0";
    
    /**土葬**/
    public static final String GLOBAL_INHUMSTION = "1";
    
    /**外运**/
    public static final String GLOBAL_OUT = "2";
    
    /**优待蓝色证件**/
    public static final String CIV_BLUECARD = "2";
    
    /**优待证黄色证件**/
    public static final String CIV_YELLOWCARD = "1";
    
    /**优待免费乘车证件**/
    public static final String CIV_FREEBUSCARD = "3";
    
    /**蓝色优待证男性年龄**/
    public static final int CIV_BLUECARDMALEAGE = 65;
    
    /**蓝色优待证女性年龄**/
    public static final int CIV_BLUECARDFEMALEAGE = 60;
    
    /**黄色优待证男性年龄**/
    public static final int CIV_YELLOWCARDMALEAGE = 70;
    
    /**黄色优待证女性年龄**/
    public static final int CIV_YELLOWCARDFEMALEAGE = 65;
    
    /**免费乘车证年龄**/
    public static final int CIV_FREEBUSCARDAGE = 65;
    
    /**
	 * 默认图片显示宽度 #2006-08-03 By Sun 
	 */
	public static final int DEFAULT_PIC_WIDTH = 550;
	/**
	 * 默认照片显示宽度 #2006-08-15 By Sun
	 */
	public static final int DEFAULT_PHOTO_WIDTH = 115;
	/**
	 * 默认照片显示高度 #2006-10-19 By Sun
	 */
	public static final int DEFAULT_PHOTO_HEIGHT = 145;
	
	/**楼栋分类最大值*/
	public static final int maxType =1;
	
	/**
	 * 分割符号
	 */
	public static final String GLOBALS_SPAN = "=";
	
	/***************以下为pda数据变更类型 #2006-09-13 By Sun**********/
	/**
	 * 原始状态
	 */
	public static final String PDA_CHANGETYPE_ORIG = "orig";
	
	/**
	 * 原始状态
	 */
	public static final String PDA_CHANGETYPE_ADD = "Add";
	
	/**
	 * 原始状态
	 */
	public static final String PDA_CHANGETYPE_MOD = "Mod";
	
	/**
	 * 原始状态	 */
	public static final String PDA_CHANGETYPE_DEL = "Del";
	
	/**
	 * pda审核状态---已审核
	 */
	public static final String PDA_WASAUDITED = "1";
	/**
	 * pda审核状态---未审核
	 */
	public static final String PDA_NOTAUDITED = "0";
	
	/***************以上为pda数据变更类型 #2006-09-13 By Sun**********/
	
	/**
	 * 从人口信息表取家庭成员
	 * #2006-08-28 
	 */
	 public static final String  HOSTRELATION = "2";
	 
	 /**
	  * 默认select的值
	  * @param rootPath
	  */
	 public static final String GLOBAL_SELECT = "-999";
	 
	 /**
	  * 默认行政区划默认值
	  * @param rootPath
	  */
	 public static final String GLOBAL_DISTRICTSELECT = "-100";	 
	
	 /**
	  * 采集员用户类型
	  * @param rootPath
	  */
	 public static final String GLOBAL_USERTYPE_GATHER = "1";
	 
	 /**
	  * 没有照片
	  * @since 2006-11-23
	  */
	 public static final String POP_NOPHOTO = "0";
	 /**
	  * 有照片
	  * @since 2006-11-23
	  */
	 public static final String POP_HASPHOTO = "1";
	 
	 /** 责任人类型 .*/
	 //第一责任人.
	 public static final String dutyFirst = "1" ;
	 //直接责任人.
	 public static final String dutyDirect = "2";
	 //督查责任人.
	 public static final String dutySupervise = "3";
	 //片区负责人.
	 public static final String dutyCommunity = "4";
	 //排查责任人.
	 public static final String dutyFilter = "5";
	 //挂点领导.
	 public static final String dutyLeader = "6";
	 //挂点科室负责人.
	 public static final String dutyOfficeLeader = "7";
	 //行业相关科室转办隐患处理责任人.
	 public static final String dutyOffice = "10";
	 
	 //行政区划.
	 public static final String community = "6";
	 
	 //重新开业.(场所状态).
	 public static final String reopen  = "6";
	 
	 //居住类型.
	 //常住.
	 public static final String usally  = "1";
	 //暂住
	 public static final String times  = "2";
	 
	 //户口类型.
	 //非农业集体户.
	 public static final String notFarming = "3";
	 //农业集体户.
	 public static final String farming = "4";
	 
	 /**
	  * 短信发送成功标记	  * @param rootPath
	  */
	 public static final String MESSAGESEND_SUCCESS = "1";
	 
	 /************ 采集卡代码：打印记录专用 **********/
	 //育妇采集卡
	 public static final String PRINTINFO_PLANFAMILY = "PLANFAMILY1";
	 //暂住人员信息登记表
	 public static final String PRINTINFO_ZULHIREPERSON = "ZULHIREPERSON1";
	 //出租采集卡
	 public static final String PRINTINFO_ZULHIREPERSON2 = "ZULHIREPERSON2";
	 //社区综合管理信息采集卡
	 public static final String PRINTINFO_POPULATE = "POPULATE";
     
	 public static final String MARKITEM_JDB = "街道办";
	 public static final String MARKITEM_SQ = "社区工作站";
	 
	 
	 //主页统计查询缓存cache的名称
	 public static final String HOME_CACHE = "homequery";
	 //户籍人口死亡处理统计表cache的名称
	 public static final String DEATH_CACHE = "deathreport";
	 //人口相关信息的cache
	 public static final String POPULATE_CACHE = "populatereport";
	 //数据统计报表cache
	 public static final String GATHER_CACHE = "gatherreport";
	 
	 //系统自动审核时，最多审核的记录条数
	 public static final int MAXAUDIT_NUM = 500;
	 
    //---------------------------------------------->常量 end
    
    public static void SetRootPath(String rootPath) {
        if (PATH == null)
            PATH = rootPath;
    }
    
    public static String getRootPath() {
        if (PATH == null || PATH.equals("")) {
            PATH = Globals.class.getResource("/").getPath();
            PATH = PATH.replaceAll("WEB-INF/classes/", "");
            PATH = BaseUtil.decodeURL(PATH, "UTF-8");           
        }
        if(PATH.indexOf("/") == 0)
        	PATH = PATH.substring(1);
        
        return PATH;
    }
    
    public static String getProvince() {
    	return getPropertyNotNull("code.province");
    }
    
    public static String getCity() {
    	return getPropertyNotNull("code.city");
    }
    
    public static String getCounty() {
    	return getPropertyNotNull("code.county");
    }
    /**
     * 判断config.xml中isCounty中的值是否为0
     * @return
     */
    public static boolean getIsCounty() {
    	
    	return getPropertyNotNull("code.isCounty").equals("0");
    	
    }
    
    public static int getPageSize() {
        return getPropertyForInt("pageSize");
    }
    
    /**
     * get the property from the xml file;
     * if the name is "a.b.c", and the xml file somehow like <a><b><c>ccc</c></b></a>;
     * then return "ccc";
     * @param name
     * @return
     */
    public static String getProperty(String name) {
        loadProperty();
        return property.getProperty(name);
    }  
    
    /**
     * get the property from the xml file; and if the value is null then return "";
     * if the name is "a.b.c", and the xml file somehow like <a><b><c>ccc</c></b></a>;
     * then return "ccc";
     * @param name
     * @return
     */
    public static String getPropertyNotNull(String name) {
        loadProperty();
        String temp = property.getProperty(name);
        if (temp == null) {
            return "";
        } else {
            return temp;
        }
    }
    
    /**
     * get the property from the xml file; and change the value to int.
     * if the name is "a.b.c", and the xml file somehow like <a><b><c>ccc</c></b></a>;
     * then return "ccc";
     * @param name
     * @return
     */
    public static int getPropertyForInt(String name) {
        String temp = getProperty(name);
        int i = 0;
        try {
            i = Integer.parseInt(temp);
        } catch (NumberFormatException e) {
            //no thing
        }
        return i;
    }
    
    /**
     * 取得同步事件时街道对应值班室部门代码

     * @param stroffice
     * @return
     */
    public static String getStrofficeDept(String stroffice){
    	String strofficeDeptString = getProperty("strofficeDept");
    	String strofficeDept[] = strofficeDeptString.split(";");
    	int l = strofficeDept.length;
    	for(int i=0;i<l;i++){
    		if(strofficeDept[i].indexOf(stroffice)!=-1){
    			return strofficeDept[i].split(",")[1];
    		}
    	}
    	return "";
    }
    
    /**
     * set the name binded to value to the xml file;
     * @param name
     * @param value
     */
    public static void setProperty(String name, String value) {
        loadProperty();
        property.setProperty(name, value);
    }
    
    /**
     * delet the name from the xml file
     * @param name
     */
    public static void deleteProperty(String name) {
        loadProperty();
        property.deleteProperty(name);
    }
    
    private synchronized static void loadProperty() {
        property = new XMLProperty(getRootPath() + "WEB-INF/config/config.xml");
    }
}
